package com.nulldev.util.uri.iwebkit2.parserJ;

import java.net.URL;

import com.nulldev.util.uri.URIUtil;
import com.nulldev.util.uri.Soup_imported.Jsoup;
import com.nulldev.util.uri.Soup_imported.nodes.Element;
import com.nulldev.util.uri.iwebkit2.document.Document;

public class Parser {

	public static Document parse(final URL url) {
		final Document doc = Document.createDocument(url.toString());
		final String html = URIUtil.downloadPageS(url);
		final com.nulldev.util.uri.Soup_imported.nodes.Document doc_parser = Jsoup.parse(html);
		for (final Element element : doc_parser.getAllElements()) {
			if (element.tagName().equals("title")) {
				final String text = element.text();
				if (text != null) {
					doc.setTitle(text);
				}
			}
			final com.nulldev.util.uri.iwebkit2.document.Element ele = ElementParser.parseElement(element);
			doc.registerElement(ele);
		}
		System.out.println(doc);
		return doc;
	}
}
